package com.chenglai.goods.dao;

import com.chenglai.goods.pojo.ProductComment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author jiang
 * @created 2023/11/16 10:07:47
 **/

@Repository
public interface ProductCommentMapper extends Mapper<ProductComment> {

    @Insert("insert into t_cl_productComment values " +
            "(#{userId},#{productId},#{comment},#{satisfaction},#{commentTime},#{orderNum},#{shopId})")
    @Options(useGeneratedKeys = true, keyProperty = "commentId")
    void addProductComment(ProductComment productComment);

    @Select("SELECT a.*,b.user_name " +
            "FROM t_cl_productComment a " +
            "LEFT JOIN t_cl_user b " +
            "ON a.user_id = b.user_id " +
            "WHERE a.product_id = #{productId} ")
    List<ProductComment> getProductComment(Integer productId);
}
